Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Change unsteady timestep using Python wrapper #2190

Closed

Conversation

j-signorelli
Copy link
Contributor

Proposed Changes

I have found it useful to be able to adaptively change deltaT using the Python wrapper -- this PR implements that functionality.

Instead of CDriver::GetUnsteadyTimeStep returning CConfig::GetTime_Step, it was updated to return the actual dimensional timestep used in iterations. A new CDriver::SetUnsteadyTimeStep function was implemented that updates both Delta_UnstTimeND and Delta_UnstTime in CConfig. A new setter function for Delta_UnstTime had to be implemented to do this as well.

A quick grep showed me that the only usage of CConfig::GetTime_Step appears to be in SU2_SOL, initialization, and outputting in the NonDimTable. However, I did see one usage of it here, which appears to be called every iteration:

const su2double TimeSync = config[iZone]->GetTime_Step()/config[iZone]->GetTime_Ref();

I can update that line if necessary to instead call CConfig::GetDelta_UnstTime. I don't believe that there are any additional issues that may be arisen beyond this.

Related Work

N/A

PR Checklist

Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

@j-signorelli j-signorelli changed the title Change unsteady timestep using Python wrapper [WIP] Change unsteady timestep using Python wrapper Dec 27, 2023
@j-signorelli j-signorelli marked this pull request as draft December 27, 2023 22:17
@j-signorelli
Copy link
Contributor Author

j-signorelli commented Dec 27, 2023

Changed to WIP, found several areas that presume a constant timestep in calculation of time I hadn't considered, like:

if (config_container[ZONE_0]->GetTime_Marching() != TIME_MARCHING::STEADY)
config_container[ZONE_0]->SetPhysicalTime(static_cast<su2double>(TimeIter)*config_container[ZONE_0]->GetDelta_UnstTimeND());

and

deltaT = config->GetDelta_UnstTimeND();
Lref = config->GetLength_Ref();
/*--- Compute delta time based on physical time step ---*/
time_new = iter*deltaT;
if (iter == 0) time_old = time_new;
else time_old = (iter-1)*deltaT;
.

I am sure there are many others, so this probably is not as straightforward as I had thought.

@j-signorelli
Copy link
Contributor Author

j-signorelli commented Dec 28, 2023

@bigfooted Has there ever been any discussion regarding implementation of a START_TIME= capability into the config file? After going through the code a bit, it looks like doing this would be a good starting point for implementing ability to adjust deltaT mid-runs, as in general the code presumes TimeIter*deltaT as being the current time. This would be problematic for unsteady restarts that have a varying timestep. Plus, this would allow one to, without using the Python wrapper, use a different timestep in the config file for an unsteady restart. It also may clear up some confusion to have an explicit option for this, as in #2071.

It can maybe look something like:

% Start time for restarting unsteady simulations
% = -1 for default calculation (START_TIME=RESTART_ITER*TIME_STEP)
START_TIME=-1

Then CConfig::GetPhysicalTime could be appropriately updated and used in-place of all locations in the code where a physical time is manually calculated.

@pcarruscag
Copy link
Member

Sounds good to implement START_TIME for the restart issue. But for what you want to do it would be better to just accumulate the dts to compute physical time

Includes a getter method in CConfig
@j-signorelli
Copy link
Contributor Author

Just want to leave some notes here, open to any thoughts or suggestions.

I think it's best to have it work something like this for 1st-order dual timestepping:

TIME_STEP=0.5
RESTART_ITER=0
----------------------------------------------------------------------
Time_Iter    Cur_Time
0                 0.0
1                 0.5
2                 1.0
----------------------------------------------------------------------
Output of restart_flow_00002.dat associated with t=1.0

Then if I want to restart that simulation but with a different timestep, I would have to make sure START_TIME represents the time at which the first iteration in the restart is completed to, NOT the time from the previous restart file:

TIME_STEP=0.25
RESTART_ITER=3
START_TIME=1.25
----------------------------------------------------------------------
Time_Iter    Cur_Time
3                 1.25

I think it may make more sense to just call it RESTART_TIME so it is consistent with RESTART_ITER.

However I don't think that this adaptive timestepping functionality / changing of timesteps for unsteady restarts would work for 2nd-order dual timestepping since information on the previous dt is lost. It wouldn't be too challenging to have a check for this in CDriver::SetUnsteadyTimestep and also a warning if START_TIME is used on an unsteady restart with it, but it may be getting a bit clunky at that point.

@j-signorelli
Copy link
Contributor Author

Closing this for now unfortunately - I will not have the time in the immediate future to work through intricacies of this. There are too many other features of SU2 that presume a dt*time_iter as the present physical time, so implementing this in a general way that accounts for these is a bit more tedious than I had expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants